﻿using UnityEngine;
using System.Collections;

public class Inspect : MonoBehaviour, IInteractiveAction {

	public string Description;

	private InteractiveObject owner;
	bool drawDescription;
	Color descriptionColor;

	// Use this for initialization
	void Start () {
		descriptionColor = Color.white;
	}

	// Update is called once per frame
	void Update () {
	
	}

	public string GetActionName() {
		return "Inspect (PressX)";
	}

	public void Execute() {
		owner = (InteractiveObject)this.gameObject.GetComponent(typeof(InteractiveObject));
		drawDescription = true;
		StartCoroutine("CallFade");
	}

	public void Stop() {
		StopAllCoroutines();
		descriptionColor.a = 0.0f;
		drawDescription = false;
	}

	public void OnGUI() {
		if (descriptionColor.a <= 0) {
			drawDescription = false;
			descriptionColor.a = 1.0f;
		}

		if (drawDescription) {
			Vector3 pos = Camera.main.WorldToScreenPoint(owner.MenuPosition.transform.position);
			GUI.color = descriptionColor;
			GUI.Label (new Rect (pos.x, (Screen.height - pos.y) + owner.actionMenu.GetHeightWithOptions(), 500, 20), Description);
		}
	}

	IEnumerator CallFade() {
		yield return new WaitForSeconds(1.0f);
		StartCoroutine("Fade");
	}

	IEnumerator Fade() {
		for (float f = 1f; f >= -1; f -= 0.1f) {

			descriptionColor.a = f;

			yield return new WaitForSeconds(.1f);
		}
	}
}
